//app.js
App({
  onLaunch: function () {
    wx.getSystemInfo({
      success: (res) => {
        //model中包含着设备信息
        console.log(res.model)
        if (res.model.search('iPhone X') != -1) {
          this.globalData.isIpx = true;
        } else {
          this.globalData.isIpx = false;
        }
      }
    })

    wx.getSetting({
      success:res=> {
        console.log('wx.getSetting')
        console.log(res)
      }
    })

    // this.getNavigationBarColor()
  },
  onShow: function () {
    console.log(getCurrentPages())
  },
  onHide: function () {
    console.log(getCurrentPages())
  },
  onError: function (msg) {
    console.log(msg)
  },
  util: require('we7/resource/js/util.js'),
  getimgUrl: function (n) {
    var url = this.globalData.imgurl;
    console.log(url, n)
    n.setData({
      url: url
    })
    var e = this;
    url || e.util.request({
      'url': 'entry/wxapp/Url',
      success: function (res) {
        console.log(res)
        e.globalData.imgurl = res.data
        e.getimgUrl(n)
      }
    })
  },
  setNavigationBarColor: function (n) {
    var t = this.globalData.color, url = this.globalData.imgurl;

    if(t){
      t = t.replace(/(^\s*)|(\s*$)/g,"")
      wx.setNavigationBarColor({
        frontColor: '#ffffff',
        backgroundColor: t,
      }); 
    }

    n.setData({
      color: t,
      url: url,
      isIpx: this.globalData.isIpx
    })
    var e = this;
    t || e.util.request({
      'url': 'entry/wxapp/system',
      success: function (t) {
		  /* 
		  * mf-8.19 设置默认语言 
		  */
		  const { lang } = t.data
		  const currentLang = lang ==='1' ? 'zh_CN' : 'wei'
		  wx.setStorageSync('Language',currentLang)
        getApp().xtxx = t.data
        e.globalData.imgurl = t.data.attachurl
        e.globalData.color = t.data.color||'#34aaff'
        e.setNavigationBarColor(n)
        // 0 == t.code && (wx.setStorageSync("_navigation_bar_color", t.data), e.setNavigationBarColor())
      }
    })
  },
  pageOnLoad: function (e) {
    var that = this;
    console.log("----setPageNavbar----"), console.log(e);
    function a(t) {
      console.log(t)
      var a = !1,
      o = e.route || e.__route__ || null;
      for (var n in t.navs) t.navs[n].url === "/" + o ? (t.navs[n].active = !0, a = !0) : t.navs[n].active = !1;
      console.log('sy3')
      console.log(a)
      e.setData({
        _navbar: t
      })
    }
    var navdata = {
      background_image:
      "", border_color: "rgba(0,0,0,.1)"
    }
    var o = that.globalData.navbar;
    console.log(o)
    o && a(o);
    o || that.util.request({
      'url': 'entry/wxapp/nav',
      success: function (t) {
        var xtxx = getApp().xtxx1
        console.log(t, xtxx)
        if (t.data.length == 0) {
          if (xtxx.model == '1') {
            var arr = [{
              logo: '/fs_wmall/img/tabindexf.png', logo2: '/fs_wmall/img/tabindex.png', title: '首页', title_color: '#34aaff', title_color2: '#888', url: "/fs_wmall/pages/index/index"
            }, {
              logo: '/fs_wmall/img/tabddf.png', logo2: '/fs_wmall/img/tabdd.png', title: '订单', title_color: '#34aaff', title_color2: '#888', url: "/fs_wmall/pages/wddd/order"
            }, {
              logo: '/fs_wmall/img/tabmyf.png', logo2: '/fs_wmall/img/tabmy.png', title: '我的', title_color: '#34aaff', title_color2: '#888', url: "/fs_wmall/pages/my/index"
            }]
          }
          if (xtxx.model == '2') {
            var arr = [{
              logo: '/fs_wmall/img/tabindexf.png', logo2: '/fs_wmall/img/tabindex.png', title: '首页', title_color: '#34aaff', title_color2: '#888', url: "/fs_wmall/pages/seller/index"
            }, {
              logo: '/fs_wmall/img/tabddf.png', logo2: '/fs_wmall/img/tabdd.png', title: '订单', title_color: '#34aaff', title_color2: '#888', url: "/fs_wmall/pages/wddd/order"
            }, {
              logo: '/fs_wmall/img/tabmyf.png', logo2: '/fs_wmall/img/tabmy.png', title: '我的', title_color: '#34aaff', title_color2: '#888', url: "/fs_wmall/pages/my/index"
            }]
          }
          if (xtxx.model == '4') {
            var arr = [{
              logo: '/fs_wmall/img/tabindexf.png', logo2: '/fs_wmall/img/tabindex.png', title: '首页', title_color: '#34aaff', title_color2: '#888', url: "/fs_wmall/pages/seller/indextakeout"
            }, {
              logo: '/fs_wmall/img/tabddf.png', logo2: '/fs_wmall/img/tabdd.png', title: '订单', title_color: '#34aaff', title_color2: '#888', url: "/fs_wmall/pages/wddd/order"
            }, {
              logo: '/fs_wmall/img/tabmyf.png', logo2: '/fs_wmall/img/tabmy.png', title: '我的', title_color: '#34aaff', title_color2: '#888', url: "/fs_wmall/pages/my/index"
            }]
          }
          navdata.navs = arr
          a(navdata)
          that.globalData.navbar = navdata
        }
        else {
          navdata.navs = t.data
          a(navdata)
          that.globalData.navbar = navdata
          // that.util.request({
          //   'url': 'entry/wxapp/url',
          //   'cachetime': '0',
          //   success: function (res) {
          //     console.log(res.data)
          //     var url = res.data
          //     for (var i in t.data) t.data[i].logo = url + t.data[i].logo, t.data[i].logo2 = url + t.data[i].logo2
          //     navdata.navs = t.data
          //     a(navdata)
          //     that.globalData.navbar = navdata
          //   }
          // });
        }
      }
    })
  },
  title:function(title){
    if(title!=''){
      wx.showModal({
        title: '',
        content: title,
      })
    }else{
      return true
    }
  },
  getUserInfo: function (cb) {
    let userInfo = wx.getStorageSync('userInfo')
    if(userInfo){
      userInfo = JSON.parse(userInfo)
    }
    typeof cb == "function" && cb(userInfo)
  },
  //sjdnav
  sjdpageOnLoad: function (e) {
    var that = this;
    console.log("----setPageNavbar----"), console.log(e);
    function a(t) {
      console.log(t)
      var a = !1,
        o = e.route || e.__route__ || null;
      for (var n in t.navs) t.navs[n].url === "/" + o ? (t.navs[n].active = !0, a = !0) : t.navs[n].active = !1;
      a && e.setData({
        _navbar: t
      })
    }
    var navdata = {
      background_image:
      "", border_color: "rgba(0,0,0,.1)"
    }
    var o = that.globalData.sjdnavbar;
    console.log(o)
    o && a(o);
    o || that.util.request({
      'url': 'entry/wxapp/nav',
      success: function (t) {
        console.log(t)
        if (0 == 0) {
          var arr = [{
            logo: '/fs_wmall/img/tabindexf.png', logo2: '/fs_wmall/img/tabindex.png', title: '外卖订单', title_color: '#34aaff', title_color2: '#888', url: "/fs_wmall/pages/sjzx/wmdd/wmdd"
          }, {
              logo: '/fs_wmall/img/tabdnf.png', logo2: '/fs_wmall/img/tabdn.png', title: '店内订单', title_color: '#34aaff', title_color2: '#888', url: "/fs_wmall/pages/sjzx/dndd/dndd"
            }, {
              logo: '/fs_wmall/img/tabglf.png', logo2: '/fs_wmall/img/tabgl.png', title: '商品管理', title_color: '#34aaff', title_color2: '#888', url: "/fs_wmall/pages/sjzx/spgl/cplb"
            },  {
              logo: '/fs_wmall/img/tabddf.png', logo2: '/fs_wmall/img/tabdd.png', title: '数据统计', title_color: '#34aaff', title_color2: '#888', url: "/fs_wmall/pages/sjzx/sjtj/sjtj"
          },{
              logo: '/fs_wmall/img/tabmyf.png', logo2: '/fs_wmall/img/tabmy.png', title: '商家中心', title_color: '#34aaff', title_color2: '#888', url: "/fs_wmall/pages/sjzx/sjzx/sjzx"
          }]
          navdata.navs = arr
          a(navdata)
          that.globalData.sjdnavbar = navdata
        }
        else {
          navdata.navs = t.data
          a(navdata)
          that.globalData.sjdnavbar = navdata
        }
      }
    })
  },
  // 解析富文本
  convertHtmlToText: function convertHtmlToText(inputText) {
    var returnText = "" + inputText;
    // returnText = returnText.replace(/<\/div>/ig, '\r\n');
    // returnText = returnText.replace(/<\/li>/ig, '\r\n');
    // returnText = returnText.replace(/<li>/ig, '  *  ');
    // returnText = returnText.replace(/<\/ul>/ig, '\r\n');
    // returnText = returnText.replace(/<br\s*[\/]?>/gi, "\r\n");
    // returnText = returnText.replace("↵", "\n");
    returnText = returnText.replace(/<p.*?>/gi, "\r\n");
    returnText = returnText.replace(/<\/p>/ig, '\r\n', '  *  ');
    // returnText = returnText.replace(/<a.*href="(.*?)".*>(.*?)<\/a>/gi, " $2 ($1)");
    // returnText = returnText.replace(/<script.*>[\w\W]{1,}(.*?)[\w\W]{1,}<\/script>/gi, "");
    // returnText = returnText.replace(/<style.*>[\w\W]{1,}(.*?)[\w\W]{1,}<\/style>/gi, "");
    // returnText = returnText.replace(/<(?:.|\s)*?>/g, "");
    // returnText = returnText.replace(/(?:(?:\r\n|\r|\n)\s*){2,}/gim, "\r\n\r\n");
    // returnText = returnText.replace(/ +(?= )/g, '');
    // returnText = returnText.replace(/ /gi, " ");
    // returnText = returnText.replace(/&/gi, "&");
    // returnText = returnText.replace(/"/gi, '"');
    // returnText = returnText.replace(/</gi, '<');
    // returnText = returnText.replace(/>/gi, '>');
    return returnText;
  },
  util: require('we7/resource/js/util.js'),
  tabBar: {
    "color": "#123",
    "selectedColor": "#1ba9ba",
    "borderStyle": "#1ba9ba",
    "backgroundColor": "#fff",
    "list": [
      {
        "pagePath": "/we7/pages/index/index",
        "iconPath": "/we7/resource/icon/home.png",
        "selectedIconPath": "/we7/resource/icon/homeselect.png",
        "text": "首页"
      },
      {
        "pagePath": "/we7/pages/user/index/index",
        "iconPath": "/we7/resource/icon/user.png",
        "selectedIconPath": "/we7/resource/icon/userselect.png",
        "text": "微擎我的"
      }
    ]
  },
  globalData: {
    userInfo: null,
  },
  siteInfo: require('siteinfo.js')
});